import { UIManager } from "../manager/UIManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class FanKuiUI extends cc.Component {
    public static instance: FanKuiUI = null;

    @property({ type: cc.EditBox, tooltip: "编辑框" })
    private editBox: cc.EditBox = null;

    @property({ type: [cc.Node], tooltip: "对勾s" })
    private selects: cc.Node[] = [];

    protected async onLoad() {
        FanKuiUI.instance = this;

        this.selects.forEach((o) => {
            const select = cc.find("select", o);
            select.active = false;
        });
    }

    private onBtnsClicked(event: cc.Event, data: cc.Event.EventCustom) {
        const name = event.target.name;
        switch (name) {
            case "btnUnselect":
                {
                    for (let i = 0; i < this.selects.length; i++) {
                        if (this.selects[i] === event.target) {
                            const select = cc.find("select", this.selects[i]);
                            select.active = !select.active;
                            break;
                        }
                    }
                }
                break;
            case "btnSubmit":
                {
                    let count = 0;
                    this.selects.forEach((o) => {
                        const select = cc.find("select", o);
                        if (select.active) {
                            count++;
                        }
                    });

                    if (count > 0 || this.editBox.string !== "") {
                        UIManager.ins.showToast("提交成功~");
                    }
                }
                break;
            case "btnClose":
                {
                    UIManager.ins.close();
                }
                break;
        }
        // console.log("onReviveClicked()===>按钮:", name);
    }
}